<template>
    <div>
        <el-dialog title="修改" :visible.sync="dialogFormVisible">
            <el-form :model="form" :rules="formRules" ref="form">
                <el-form-item label="活动名称" :label-width="formLabelWidth" prop="log">
                    <el-input v-model="form.log" autocomplete="off"></el-input>
                </el-form-item>
                <el-form-item label="活动名称" :label-width="formLabelWidth" prop="integral">
                    <el-input v-model="form.integral" autocomplete="off"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="upLoadRule">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    export default {
        name: "rules-dialog.vue",
        data() {
            return {
                form: {
                    log: '',
                    integral: ''
                },
                formRules: {
                    log: [
                        {
                            required: true, message: '请输入获取积分途径', trigger: 'blur'
                        }
                    ],
                    integral: [
                        {
                            required: true, message: '请输入可获取积分数量', trigger: 'blur'
                        }
                    ]
                },
                formLabelWidth: '100px',
                dialogFormVisible: false
            }
        },
        methods: {
            upLoadRule() {
                this.$refs.form.validate((valid) => {
                    if(valid) {
                        this.resetFun()
                    }else {
                        this.$message.error('修改失败，请重新修改')
                        return false
                    }
                })
            },
            async resetFun() {
                const data = await this.$Http.resetIntegralRule({
                    pro: JSON.stringify(this.form)
                })
                if(data.code === 200) {
                    this.$message.success('修改已完成！')
                    this.dialogFormVisible = false
                    this.$emit('reloadRules')
                }
            }
        }
    }
</script>

<style scoped>

</style>
